#! /usr/bin/env perl
# author: maxiao
# date: 2023-03-09 14:29
# description: 测试多条件结构

use v5.20;
use strict;
use utf8;
use warnings;

# 更改输入输出设置
binmode STDIN, ':encoding(UTF-8)';
binmode STDOUT, ':encoding(UTF-8)';

# if...elsif...else...结构
sub if_struct {
    my $score = @_[0];
    if ( $score < 60 ) {
        print "不合格\n";
    } elsif ( $score < 80 ) {
        print "合格\n";
    } elsif ( $score < 90 ) {
        print "良好\n";
    } else {
        print "优秀\n";
    }
}

sub condition_operator {
    my $result =
        ( @_[0] < 60 ) ? "不合格" :
        ( @_[0] < 80 ) ? "合格" :
        ( @_[0] < 90 ) ? "良好" :
                        "优秀";
    print "$result\n";
}


while (1) {
    print "please input your score : ";
    chomp(my $input = <STDIN>);
    if ( $input < 0 or $input > 100 ) {
        redo;
    }
    print "if ... elsif ... else ...运行结果如下:\n";
    &if_struct($input);
    print "\n";
    print "通过条件操作符expresion ? expr1 : expr2 运行结果如下:\n";
    &condition_operator($input);
}
    
